package cn.com.egova.erp.dao.impl;

import cn.com.egova.erp.dao.IStoreoperDao;
import cn.com.egova.erp.entity.Storeoper;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

/**
 * 仓库操作记录数据访问类
 *
 * @author Administrator
 */
public class StoreoperDao extends BaseDao<Storeoper> implements IStoreoperDao {

    /**
     * 构建查询条件
     *
     * @param storeoper1
     * @param storeoper2
     * @param param
     * @return
     */
    public DetachedCriteria getDetachedCriteria(Storeoper storeoper1, Storeoper storeoper2, Object param) {
        DetachedCriteria dc = DetachedCriteria.forClass(Storeoper.class);
        if (storeoper1 != null) {
            //员工
            if (null != storeoper1.getEmpuuid()) {
                dc.add(Restrictions.eq("empuuid", storeoper1.getEmpuuid()));
            }
            //仓库编号
            if (null != storeoper1.getStoreuuid()) {
                dc.add(Restrictions.eq("storeuuid", storeoper1.getStoreuuid()));
            }
            //商品编号
            if (null != storeoper1.getGoodsuuid()) {
                dc.add(Restrictions.eq("goodsuuid", storeoper1.getGoodsuuid()));
            }
            //操作时间
            if (null != storeoper1.getOpertime()) {
                dc.add(Restrictions.ge("opertime", storeoper1.getOpertime()));
            }
            //操作类型
            if (null != storeoper1.getType() && storeoper1.getType().trim().length() > 0) {
                dc.add(Restrictions.eq("type", storeoper1.getType()));
            }
        }

        if (storeoper2 != null) {
            if (null != storeoper2.getOpertime()) {
                dc.add(Restrictions.le("opertime", storeoper2.getOpertime()));
            }
        }
        return dc;
    }

}
